package pt.compflow.client.ui;

import java.util.HashMap;
import java.util.Map;

import org.restlet.representation.EmptyRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;

import pt.compflow.Context;
import pt.compflow.flowontology.model.FlowOntologyModel;
import pt.compflow.flowontology.model.Person;
import pt.compflow.storage.TripleStoreConnection;

public class ProfileUIResource extends UIBaseResource {

//	private static final Logger LOG = LoggerFactory.getLogger(PersonResource.class);
	
	@Get
	public Representation get() {
		Context context = getCompFlowContext();
		TripleStoreConnection store = context.getStoreConnection();
		store.openStore();
		
		FlowOntologyModel model = store.connectModel();
		
		Person p = getPerson(model, null);
		if(p == null) {
			redirectSeeOther("/_login");
			store.closeStore();
			return new EmptyRepresentation();
		}
		
		Map<String, Object> argumentMap = new HashMap<String, Object>();
		argumentMap.put("person", getPersonMap(model, p, false));
		
		store.closeStore();
			
		return getTemplateRepresentation("ProfileTemplate.ftl", argumentMap);
	}
	
}
